﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

// Token: 0x02000365 RID: 869
public static class NullCheck
{
	// Token: 0x060015AC RID: 5548 RVA: 0x00092CCC File Offset: 0x00090ECC
	public static T GetCache<T>(this object _, ref T ret, Func<T> get)
	{
		return (ret == null) ? (ret = get()) : ret;
	}

	// Token: 0x060015AD RID: 5549 RVA: 0x00092D04 File Offset: 0x00090F04
	public static T GetCacheObject<T>(this object _, ref T ret, Func<T> get) where T : UnityEngine.Object
	{
		return (!(ret != null)) ? (ret = get()) : ret;
	}

	// Token: 0x060015AE RID: 5550 RVA: 0x00092D44 File Offset: 0x00090F44
	public static T GetComponentCache<T>(this Component component, ref T ret) where T : Component
	{
		return component.GetCacheObject(ref ret, () => component.GetComponent<T>());
	}

	// Token: 0x060015AF RID: 5551 RVA: 0x00092D78 File Offset: 0x00090F78
	public static T GetComponentCache<T>(this GameObject gameObject, ref T ret) where T : Component
	{
		return gameObject.GetCacheObject(ref ret, () => gameObject.GetComponent<T>());
	}

	// Token: 0x060015B0 RID: 5552 RVA: 0x00092DAC File Offset: 0x00090FAC
	public static T GetOrAddComponent<T>(this Component component) where T : Component
	{
		return (!(component == null)) ? component.gameObject.GetOrAddComponent<T>() : ((T)((object)null));
	}

	// Token: 0x060015B1 RID: 5553 RVA: 0x00092DD0 File Offset: 0x00090FD0
	public static T GetOrAddComponent<T>(this GameObject gameObject) where T : Component
	{
		if (gameObject == null)
		{
			return (T)((object)null);
		}
		T t = gameObject.GetComponent<T>();
		if (t == null)
		{
			t = gameObject.AddComponent<T>();
		}
		return t;
	}

	// Token: 0x060015B2 RID: 5554 RVA: 0x00092E10 File Offset: 0x00091010
	public static bool IsNullOrWhiteSpace(this string self)
	{
		return self == null || self.Trim() == string.Empty;
	}

	// Token: 0x060015B3 RID: 5555 RVA: 0x00092E2C File Offset: 0x0009102C
	public static bool IsNullOrEmpty(this string self)
	{
		return string.IsNullOrEmpty(self);
	}

	// Token: 0x060015B4 RID: 5556 RVA: 0x00092E34 File Offset: 0x00091034
	public static bool IsNullOrEmpty(this string[] args, int index)
	{
		bool ret = false;
		args.SafeGet(index).SafeProc(delegate(string s)
		{
			ret = !s.IsNullOrEmpty();
		});
		return !ret;
	}

	// Token: 0x060015B5 RID: 5557 RVA: 0x00092E70 File Offset: 0x00091070
	public static bool IsNullOrEmpty(this List<string> args, int index)
	{
		bool ret = false;
		args.SafeGet(index).SafeProc(delegate(string s)
		{
			ret = !s.IsNullOrEmpty();
		});
		return !ret;
	}

	// Token: 0x060015B6 RID: 5558 RVA: 0x00092EAC File Offset: 0x000910AC
	public static bool IsNullOrEmpty<T>(this IList<T> self)
	{
		return self == null || self.Count == 0;
	}

	// Token: 0x060015B7 RID: 5559 RVA: 0x00092EC0 File Offset: 0x000910C0
	public static bool IsNullOrEmpty<T>(this List<T> self)
	{
		return self == null || self.Count == 0;
	}

	// Token: 0x060015B8 RID: 5560 RVA: 0x00092ED4 File Offset: 0x000910D4
	public static bool IsNullOrEmpty(this MulticastDelegate self)
	{
		return self == null || self.GetInvocationList() == null || self.GetInvocationList().Length == 0;
	}

	// Token: 0x060015B9 RID: 5561 RVA: 0x00092EF8 File Offset: 0x000910F8
	public static bool IsNullOrEmpty(this UnityEvent self)
	{
		return self == null || self.GetPersistentEventCount() == 0;
	}

	// Token: 0x060015BA RID: 5562 RVA: 0x00092F0C File Offset: 0x0009110C
	public static bool IsNullOrEmpty(this UnityEvent self, int target)
	{
		return self.IsNullOrEmpty() || self.GetPersistentTarget(target) == null || self.GetPersistentMethodName(target).IsNullOrEmpty();
	}

	// Token: 0x060015BB RID: 5563 RVA: 0x00092F3C File Offset: 0x0009113C
	public static T SafeGet<T>(this T[] array, int index)
	{
		if (array == null)
		{
			return default(T);
		}
		return ((ulong)index >= (ulong)((long)array.Length)) ? default(T) : array[index];
	}

	// Token: 0x060015BC RID: 5564 RVA: 0x00092F7C File Offset: 0x0009117C
	public static bool SafeProc<T>(this T[] array, int index, Action<T> act)
	{
		return array.SafeGet(index).SafeProc(act);
	}

	// Token: 0x060015BD RID: 5565 RVA: 0x00092F8C File Offset: 0x0009118C
	public static T SafeGet<T>(this List<T> list, int index)
	{
		if (list == null)
		{
			return default(T);
		}
		return ((ulong)index >= (ulong)((long)list.Count)) ? default(T) : list[index];
	}

	// Token: 0x060015BE RID: 5566 RVA: 0x00092FCC File Offset: 0x000911CC
	public static bool SafeProc<T>(this List<T> list, int index, Action<T> act)
	{
		return list.SafeGet(index).SafeProc(act);
	}

	// Token: 0x060015BF RID: 5567 RVA: 0x00092FDC File Offset: 0x000911DC
	public static bool SafeProc(this string[] args, int index, Action<string> act)
	{
		if (args.IsNullOrEmpty(index))
		{
			return false;
		}
		act.Call(args[index]);
		return true;
	}

	// Token: 0x060015C0 RID: 5568 RVA: 0x00092FF8 File Offset: 0x000911F8
	public static bool SafeProc(this List<string> args, int index, Action<string> act)
	{
		if (args.IsNullOrEmpty(index))
		{
			return false;
		}
		act.Call(args[index]);
		return true;
	}

	// Token: 0x060015C1 RID: 5569 RVA: 0x00093018 File Offset: 0x00091218
	public static bool SafeProc<T>(this T self, Action<T> act)
	{
		bool flag = self != null;
		if (flag)
		{
			act.Call(self);
		}
		return flag;
	}

	// Token: 0x060015C2 RID: 5570 RVA: 0x00093040 File Offset: 0x00091240
	public static bool SafeProcObject<T>(this T self, Action<T> act) where T : UnityEngine.Object
	{
		bool flag = self != null;
		if (flag)
		{
			act.Call(self);
		}
		return flag;
	}

	// Token: 0x060015C3 RID: 5571 RVA: 0x00093068 File Offset: 0x00091268
	public static void Call(this Action action)
	{
		if (action != null)
		{
			action();
		}
	}

	// Token: 0x060015C4 RID: 5572 RVA: 0x00093078 File Offset: 0x00091278
	public static void Call<T>(this Action<T> action, T arg)
	{
		if (action != null)
		{
			action(arg);
		}
	}

	// Token: 0x060015C5 RID: 5573 RVA: 0x00093088 File Offset: 0x00091288
	public static void Call<T1, T2>(this Action<T1, T2> action, T1 arg1, T2 arg2)
	{
		if (action != null)
		{
			action(arg1, arg2);
		}
	}

	// Token: 0x060015C6 RID: 5574 RVA: 0x00093098 File Offset: 0x00091298
	public static void Call<T1, T2, T3>(this Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
	{
		if (action != null)
		{
			action(arg1, arg2, arg3);
		}
	}

	// Token: 0x060015C7 RID: 5575 RVA: 0x000930AC File Offset: 0x000912AC
	public static TResult Call<TResult>(this Func<TResult> func, TResult result = default(TResult))
	{
		return (func == null) ? result : func();
	}

	// Token: 0x060015C8 RID: 5576 RVA: 0x000930C0 File Offset: 0x000912C0
	public static TResult Call<T, TResult>(this Func<T, TResult> func, T arg, TResult result = default(TResult))
	{
		return (func == null) ? result : func(arg);
	}

	// Token: 0x060015C9 RID: 5577 RVA: 0x000930D8 File Offset: 0x000912D8
	public static TResult Call<T1, T2, TResult>(this Func<T1, T2, TResult> func, T1 arg1, T2 arg2, TResult result = default(TResult))
	{
		return (func == null) ? result : func(arg1, arg2);
	}

	// Token: 0x060015CA RID: 5578 RVA: 0x000930F0 File Offset: 0x000912F0
	public static TResult Call<T1, T2, T3, TResult>(this Func<T1, T2, T3, TResult> func, T1 arg1, T2 arg2, T3 arg3, TResult result = default(TResult))
	{
		return (func == null) ? result : func(arg1, arg2, arg3);
	}

	// Token: 0x060015CB RID: 5579 RVA: 0x00093108 File Offset: 0x00091308
	public static bool Proc<T>(this T self, Func<T, bool> conditional, Action<T> act)
	{
		bool flag = conditional(self);
		if (flag)
		{
			act.Call(self);
		}
		return flag;
	}

	// Token: 0x060015CC RID: 5580 RVA: 0x0009312C File Offset: 0x0009132C
	public static bool Proc<T>(this T self, Func<T, bool> conditional, Action<T> actTrue, Action<T> actFalse)
	{
		bool flag = conditional(self);
		self.Proc((T _) => true, (!flag) ? actFalse : actTrue);
		return flag;
	}
}
